package com.ruoyi.web.controller.travel;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.travel.domain.TravelItineraryContent;
import com.ruoyi.travel.service.ITravelItineraryContentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/travel/itinerary/content")
public class TravelItineraryContentController extends BaseController {

    @Autowired
    private ITravelItineraryContentService contentService;

    /** 根据行程ID查询内容 */
    @GetMapping("/list")
    public AjaxResult listByItineraryId(Long itineraryId) {
        return success(contentService.selectByItineraryId(itineraryId));
    }

    /** 批量保存行程内容 */
    @PreAuthorize("@ss.hasPermi('travel:itinerary:edit')")
    @Log(title = "行程内容", businessType = BusinessType.INSERT)
    @PostMapping("/batch")
    public AjaxResult batchSave(@RequestBody List<TravelItineraryContent> contents) {
        return toAjax(contentService.batchInsert(contents));
    }

    /** 删除指定行程的所有内容 */
    @PreAuthorize("@ss.hasPermi('travel:itinerary:edit')")
    @Log(title = "行程内容", businessType = BusinessType.DELETE)
    @DeleteMapping("/{itineraryId}")
    public AjaxResult deleteByItineraryId(@PathVariable Long itineraryId) {
        return toAjax(contentService.deleteByItineraryId(itineraryId));
    }
}
